import cache from '../../enum/cache'
import Information from '../../model/information'
import User from '../../model/user'
import { getDataSet } from '../../utils/util';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    imageBaseUrl:getApp().globalData.imageBaseUrl,
    // username:'18992036807', // 专家
    // password:'123456',
    username:'',
    password:'',
    //  username:'xmdw', // wtdw
    // password:'123456',
    loginTypes:['专家登录','委托单位登录']
  },
  // field绑定值
  setValue(e) {
    const field = getDataSet(e, 'field')
    this.setData({
        [`${field}`]: e.detail
    })
  },
  handleLogin: async function() {
    wx.showLoading({
      title: '正在登录',
      mask: true
    })
  try {
    let query = {
      username: this.data.username,
      password: this.data.password,
    }
      let res = await User.login(query);
      if(res.code === 200){
      await Information.getMyRoles()  
      wx.switchTab({
        url: '/pages/home/index',
        success: function (e) {
          var page = getCurrentPages().pop();
          if (page == undefined || page == null) return;
          page.onLoad();
        }
      })
    } 
  } catch (e) {
      // wx.showModal({
      //     title: '注意',
      //     content: '登录失败，请稍后重试',
      //     showCancel: false
      // })
  }
  wx.hideLoading()
  }
})